package com.woniuxy.rbac.web;

import com.woniuxy.rbac.service.CourseService;
import com.woniuxy.rbac.service.GradeService;
import com.woniuxy.rbac.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller()
@RequestMapping("course")
public class CourseController {
    @Autowired
    private CourseService courseService;
    @Autowired
    private SubjectService subjectService;
    @Autowired
    private GradeService gradeService;

    @GetMapping("list")
    public String list(Model model) {
        model.addAttribute("subjects", subjectService.list());
//        model.addAttribute("grades", gradeService.list());
        return "course_list";
    }

    @GetMapping("view/{id}")
    public String view(@PathVariable("id") Integer id, Model model) {
        model.addAttribute("course", courseService.getById(id));
        return "course_view";
    }
}
